package com.hd.determine.modules.alarm;

import com.hd.common.constant.BizConstant;
import com.hd.determine.modules.alarm.determine.judges.FatigueDeterminer;
import com.hd.determine.modules.alarm.determine.judges.NightNoEntryDeterminer;
import com.hd.determine.modules.alarm.determine.judges.OffGpsDeterminer;
import com.hd.determine.modules.alarm.determine.judges.OffLineDeterminer;
import com.hd.determine.modules.alarm.model.AlarmRule;
import com.hd.determine.modules.vehicle.model.VehicleEndPos;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author chentl
 * @version V1.0
 * @Project 交通运输第三方监测平台
 * @Title Determiner.java
 * @Description 抽象研判者
 * @Package com.hd.sup.modules.alarm.determine
 * @date 2021/1/29 11:20 上午
 * @Copyright: 深圳市宏电技术股份有限公司 All rights reserved.
 */
@Slf4j
@Data
@Component
public abstract class Determiner<T> {


    public Determiner(T data, AlarmRule alarmRule) {
        this.data = data;
        this.alarmRule = alarmRule;
    }


    /**
     * @Description 研判对象
     * @Author chentl
     * @Create: 2021/1/29 11:53 上午
     */
    public T data;

    /**
     * @Description 停止?
     * @Author chentl
     * @Create: \ 11:54 上午
     */
    public boolean needStop;

    /**
     * @Description 产生?
     * @Author chentl
     * @Create: 2021/1/29 11:54 上午
     */
    public boolean needProduce;

    /**
     * @Description 研判规则
     * @Author chentl
     * @Create: 2021/1/29 11:21 上午
     */
    public AlarmRule alarmRule;

    /**
     * @return void
     * @author chentl
     * @description 开始研判
     * @date 2021/1/29 11:26 上午
     * @params []
     */
    public void startDetermine() {
    }

    /**
     * @return T
     * @author chentl
     * @description 返回对应研判者
     * @date 2021/1/29 1:08 下午
     * @params [alarmType]
     */
    public static <T extends Determiner<VehicleEndPos>> T getDeterminer(BizConstant.AlarmType alarmType, VehicleEndPos data, AlarmRule alarmRule, boolean ignore) {
        try {
            if (ignore) return null;

            if (BizConstant.AlarmType.OFF_GPS.equals(alarmType))
                return (T) new OffGpsDeterminer(data, alarmRule);
            if (BizConstant.AlarmType.OFF_LINE.equals(alarmType))
                return (T) new OffLineDeterminer(data, alarmRule);
            if (BizConstant.AlarmType.FATIGUE_DRIVE.equals(alarmType))
                return (T) new FatigueDeterminer(data, alarmRule);
            if (BizConstant.AlarmType.NIGHT_NO_ENTRY.equals(alarmType))
                return (T) new NightNoEntryDeterminer(data, alarmRule);
            //TODO 扩展新的报警研判


            log.error("[supervise] 未配置报警类型：{}  对应的研判对象, 当前规则的研判跳过", alarmType.key());
            return null;
        } catch (Exception e) {
            log.error("[supervise] 转换研判对象失败", e);
            return null;
        }

    }


}
